
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>1、Java并发模型与内存模型 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>1、Java并发模型与内存模型 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">Java内存模型（JMM）的核心目标是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Java内存模型（JMM）的核心目标是保证不同线程之间的可见性（一个线程对共享变量的修改对其他线程可见）和操作的有序性（程序的执行顺序应当保持一致）。</div>
          </div>
          <div class="card-source">来源: 3. Java内存模型（JMM）概述</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">概念</div>
          <div class="card-question">请描述Java线程在其生命周期中的六种状态。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">概念</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Java线程的六种状态包括：NEW（已创建但未启动）、RUNNABLE（正在等待操作系统调度运行）、BLOCKED（因等待锁资源而被阻塞）、WAITING（等待另一线程的通知）、TIMED_WAITING（在指定时间内等待）和TERMINATED（已执行完毕或异常终止）。</div>
          </div>
          <div class="card-source">来源: 2. 线程的生命周期与状态转换</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">synchronized关键字背后的实现机制是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">synchronized的实现基于“监视器锁”（Monitor Lock）机制。每个Java对象都有一个与之关联的锁，当一个线程执行synchronized代码块时，它必须先获取该对象的锁。</div>
          </div>
          <div class="card-source">来源: 5. synchronized的实现与锁的机制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">volatile关键字在多线程环境中主要提供哪两大保证？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">volatile关键字主要提供两大保证：1. 内存可见性，确保对变量的写操作对其他线程立即可见；2. 禁止指令重排序，确保与该变量相关的操作的有序性。</div>
          </div>
          <div class="card-source">来源: 6. volatile的原理与内存可见性</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">什么是指令重排？JMM是如何利用内存屏障来解决这个问题的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">指令重排是JVM为了优化性能而可能对指令执行顺序进行的调整。JMM通过插入内存屏障（一种特殊的CPU指令）来防止特定的操作被重排，从而保证操作的有序性。</div>
          </div>
          <div class="card-source">来源: 4. JMM的内存屏障与指令重排</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">为了优化性能，JVM对synchronized锁采用了怎样的升级策略？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">JVM使用锁的升级策略来优化性能，包括偏向锁（用于单线程场景）、轻量级锁（用于竞争较少的场景）和重量级锁（用于高竞争的场景）。</div>
          </div>
          <div class="card-source">来源: 5. synchronized的实现与锁的机制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在Java中，调用一个对象的wait()或notify()方法有什么前提条件？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">线程必须持有该对象的监视器锁才能调用wait()或notify()方法。这些方法依赖于每个对象内置的监视器锁。</div>
          </div>
          <div class="card-source">来源: 7. 线程间通信：wait/notify机制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">比较</div>
          <div class="card-question">根据文档，volatile和synchronized在功能上有何关键区别？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">比较</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">关键区别在于：volatile只能保证单一变量的可见性，而synchronized则可以保证整个代码块的原子性。</div>
          </div>
          <div class="card-source">来源: 6. volatile的原理与内存可见性</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">除了直接使用Thread类，Java还提供了哪些更高效的线程管理方案？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Java提供了Executor框架和ForkJoinPool。Executor框架提供了高效灵活的线程池管理方案，而ForkJoinPool则用于执行分治任务，通过工作窃取算法实现高效并行化。</div>
          </div>
          <div class="card-source">来源: 1. Java并发模型概述</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
